﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class property_item : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "House to let";
        string sId = Request["a"];

        int pomlingAddressID = 0;

        if ((string.IsNullOrEmpty(sId)) || (!Int32.TryParse(sId, out pomlingAddressID))) // && (string.IsNullOrEmpty(Globals.ErrorString)))
            Response.Redirect("properties_list.aspx");
        // id = 1;
        List<PomplingProperty> basicPropertyInfoList = PomplingProperty.SelectPageProperty(pomlingAddressID);

        if (basicPropertyInfoList.Count == 0)
            return;
        PomplingProperty property = basicPropertyInfoList[0];
        DivlettingPageInfoLeft.InnerHtml = BuildMainPropertyImage(property);
        DivRightOfMainImage.InnerHtml = BuildBasicPropertyInfoRight(property);
        DivSmallImageList.InnerHtml = BuildImageList(pomlingAddressID);
        List<PropertyAttribute> webAttributeList = PropertyAttribute.SelectpropertyAttributes( pomlingAddressID);
        string lettingInfoAttributes =

        DivlettingPageInfo.InnerHtml = BuildLettingInfoAttributes(webAttributeList);


        //TxtEnquiryType.Text = property.AddressLine1 + " " + property.Postcode;
    }
    private string BuildImageList(int pomplingAddressID)
    {
        List<PropertyImage> propertyImages = PropertyImage.SelectAllPropertyImages(pomplingAddressID);
        string htmlImageList = @"<ul>";
        for (int i = 0; i < propertyImages.Count; i++)
        {
            if (i == 0)
                htmlImageList += "<li><img style=\"border-width:5px;border-style:solid;border-color:#FE642E;\" class=\"ClsSmallImageList\" src=\"" + "./" + propertyImages[i].DisplayPicturePath + "\" onclick=\"Swap(this)\"/></li>";
            else
                htmlImageList += "<li><img class=\"ClsSmallImageList\" src=\"" + "./" + propertyImages[i].DisplayPicturePath + "\" onclick=\"Swap(this)\"/></li>";
        }
        htmlImageList += "</ul>";
        return htmlImageList;
    }

    private string BuildLettingInfoAttributes(List<PropertyAttribute> webAttributeList)
    {
        string lettingInfoAttributes = Environment.NewLine + "<div style=clear:both;>";
        for (int i = 0; i < webAttributeList.Count; i++)
        {
            lettingInfoAttributes += "<p style=\"color: #f58221;margin:0px;\"><strong>" + webAttributeList[i].LookupText + "</strong></p>";
            lettingInfoAttributes += "<p style=\"background-color:#fffcbc;margin-bottom:10px;margin-top:1px\">" + webAttributeList[i].AttributeDescription + "</p>";
        }
        lettingInfoAttributes += "</div>";
        return lettingInfoAttributes;
    }
    private string BuildMainPropertyImage(PomplingProperty basicPropertyInfo)
    {
        string sPropertyMainImage = " " +
           "<img src=\"" + "./" + basicPropertyInfo.DisplayPicturePath + "\" title=\"" + basicPropertyInfo.AddressLine1 + "\" alt=\"" + basicPropertyInfo.AddressLine1 + "\" " +
           " height=\"350px\" width=\"340px\" class=\"mainPropertyImage\" name=\"mainPic\" /> ";
        return sPropertyMainImage;
    }

    private string BuildBasicPropertyInfoRight(PomplingProperty basicPropertyInfo)
    {
        string sBasicPropertyInfo = " <p>" + basicPropertyInfo.PricePerCalendarMonth.ToString("0") + " PM</p>" +
           " <p>" + basicPropertyInfo.NumberOfBedrooms + ((basicPropertyInfo.NumberOfBedrooms == 1) ? " bedroom" : " Bedrooms") + "</p>" +
           " <p>" + basicPropertyInfo.Postcode + "</p>" +
           " <p>" + basicPropertyInfo.LongDescription + "</p>";
        return sBasicPropertyInfo;
    }
}